package request

import (
	"github.com/astaxie/beego/validation"
	"shop-common/utils"
	"shop-common/utils/pagehelper"
)

type NoticePageRequest struct {
	pagehelper.SearchPageRequest
	IsTop int `json:"isTop" form:"isTop"`
}

type NoticeRequest struct {
	Id            uint   `json:"id"`                                    //主键
	IsTop         int    `json:"isTop" binding:"required" default:"1"`  //置顶（2:是 1:否） 必填
	Title         string `json:"title" binding:"required"`              //公告标题 必填
	Status        int    `json:"status" binding:"required" default:"1"` //状态 2 公布 1 撤回 必填
	Content       string `json:"content" binding:"required"`            //公告内容 必填
	FileIds       []uint `json:"fileIds"`                               //图片列表
	ExpireFileIds []uint `json:"expireFileIds"`                         //过期图片
}

func (n *NoticeRequest) Valid(v *validation.Validation) {
	if n.Title == "" {
		v.SetError("Title", "公告标题不能为空")
	} else if n.Content == "" {
		v.SetError("Content", "公告内容不能为空")
	} else if !utils.IntIncludes([]int{1, 2}, n.Status) {
		v.SetError("Status", "公告状态不合法")
	} else if !utils.IntIncludes([]int{1, 2}, n.IsTop) {
		v.SetError("IsTop", "公告置顶不合法")
	}
}
